<!DOCTYPE html>
<!-- 程序的主入口 -->
<!-- 用来识别和验证UserHash，以达到根据登录状态跳转不同页面的效果 -->
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<script src="./Common/js/tools.js"></script>
		<script src="./Common/js/status_bar.js"></script>
		<style>
			body {
				background-color: white;
			}
			#Error {
				opacity: 0;
				position: absolute;
				width: 100%;
				height: 10vw;
				top: 0vh;
				text-align: center;
			}
			@keyframes ShowError{
				0%{
					opacity: 0;
				}
				50%{
					opacity: 0;
					top: calc(50% - 50vw);
				}
			}
			#Error.Show {
				animation: ShowError;
				animation-duration: 1.5s;
				opacity: 1;
				top: calc(50% - 10vw);
			}
		</style>
	</head>
	<body>
		<div id="Error">
			<h4>需要网络连接</h4><br />
			<p id="ErrorMessage">将在10秒后重试</p>
		</div>
	</body>
	<script>
		
		document.addEventListener('plusready', function() {
			// version
			plus.storage.setItem('version', '1.3.14');
			DoWait();
			var statusbarHeight = 0;
			if (plus.navigator.isImmersedStatusbar()) {
				//获取系统状态栏高度
				if (plus.os.name == "iOS") {
					if (screen.height >= 812 && screen.width == 375) {
						//是iphoneX
						statusbarHeight = 44;
					} else {
						//不是iphoneX
						statusbarHeight = 20;
					}
				} else {
					statusbarHeight = plus.navigator.getStatusbarHeight();
				}
			}
			plus.storage.setItem('statusbarHeight', statusbarHeight.toString());
			plus.cache.clear(function() {
				CheckUpdate(checkUserHash, badConnect);
			});
		});

		function checkUserHash() {
			//plus.storage.setItem("userHash", "f2187cb2ffd4d17a50d36d7ac657e9d6+13754821500");
			var userHash = plus.storage.getItem("userHash");
			if (userHash == null) {
				location.replace("./Login/login.html");
				return;
			}
			console.log(userHash)
			CallAJAX("getPhoneNoByUserHash", userHash, function(data) {
				DontWait();
				if (data["res"] == "ok" && data["phoneNo"].length >= 5)
					location.replace("./Index/index.html");
				else
					location.replace("./Login/login.html");
			}, function() {
				badConnect();
			});
		}

		function badConnect() {
			DontWait();
			plus.nativeUI.toast("请检查网络连接");
			document.getElementById('Error').classList.add('Show');
			setTimeout(function() {
				location.reload();
			}, 10000);
			for (let i = 10; i >= 1; --i) {
				setTimeout(function() {
					document.getElementById('ErrorMessage').textContent = '将在' + (10 - i) + '秒后重试'
				}, 1000 * i);
			}
		}
	</script>
</html>
